<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mission Config Form</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            padding: 0;
        }
        fieldset {
            margin-bottom: 15px;
            padding: 15px;
            border-radius: 5px;
            border: 1px solid #ccc;
        }
        legend {
            font-weight: bold;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"], input[type="number"], select {
            width: 100%;
            padding: 8px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        button {
            padding: 10px 20px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>

<h1>Mission Configuration Form</h1>

<form id="missionForm">
    <fieldset>
        <legend>Mission Config</legend>
        <label for="flyToWaylineMode">Fly To Wayline Mode:</label>
        <select id="flyToWaylineMode" name="flyToWaylineMode">
            <option value="safely">Safely</option>
            <!-- Add other options as needed -->
        </select>

        <label for="finishAction">Finish Action:</label>
        <select id="finishAction" name="finishAction">
            <option value="goHome">Go Home</option>
            <!-- Add other options as needed -->
        </select>

        <label for="exitOnRCLost">Exit On RC Lost:</label>
        <select id="exitOnRCLost" name="exitOnRCLost">
            <option value="goContinue">Go Continue</option>
            <!-- Add other options as needed -->
        </select>

        <label for="executeRCLostAction">Execute RC Lost Action:</label>
        <select id="executeRCLostAction" name="executeRCLostAction">
            <option value="hover">Hover</option>
            <!-- Add other options as needed -->
        </select>

        <label for="takeOffSecurityHeight">Take Off Security Height (m):</label>
        <input type="number" id="takeOffSecurityHeight" name="takeOffSecurityHeight" value="20">

        <label for="globalTransitionalSpeed">Global Transitional Speed (m/s):</label>
        <input type="number" id="globalTransitionalSpeed" name="globalTransitionalSpeed" value="10">

        <label for="droneEnumValue">Drone Enum Value:</label>
        <input type="number" id="droneEnumValue" name="droneEnumValue" value="67">

        <label for="droneSubEnumValue">Drone Sub Enum Value:</label>
        <input type="number" id="droneSubEnumValue" name="droneSubEnumValue" value="0">

        <label for="payloadEnumValue">Payload Enum Value:</label>
        <input type="number" id="payloadEnumValue" name="payloadEnumValue" value="52">

        <label for="payloadPositionIndex">Payload Position Index:</label>
        <input type="number" id="payloadPositionIndex" name="payloadPositionIndex" value="0">
    </fieldset>

    <fieldset>
        <legend>Folder</legend>
        <label for="templateId">Template ID:</label>
        <input type="number" id="templateId" name="templateId" value="0">

        <label for="executeHeightMode">Execute Height Mode:</label>
        <input type="text" id="executeHeightMode" name="executeHeightMode" value="WGS84">

        <label for="waylineId">Wayline ID:</label>
        <input type="number" id="waylineId" name="waylineId" value="0">

        <label for="autoFlightSpeed">Auto Flight Speed (m/s):</label>
        <input type="number" id="autoFlightSpeed" name="autoFlightSpeed" value="10">
    </fieldset>

    <fieldset id="placemarkFieldset">
        <legend>Placemarks</legend>
        <!-- Dynamically add Placemarks here -->
    </fieldset>

    <button type="button" id="addPlacemarkBtn">Add Placemark</button>
    <button type="submit">Submit</button>
</form>

<script>
    document.getElementById('addPlacemarkBtn').addEventListener('click', function() {
        const placemarkFieldset = document.getElementById('placemarkFieldset');
        const placemarkIndex = placemarkFieldset.children.length;

        const newPlacemark = document.createElement('div');
        newPlacemark.innerHTML = `
                <fieldset>
                    <legend>Placemark ${placemarkIndex}</legend>
                    <label for="coordinates_${placemarkIndex}">Coordinates:</label>
                    <input type="text" id="coordinates_${placemarkIndex}" name="Placemark[${placemarkIndex}][coordinates]" placeholder="longitude,latitude">

                    <label for="executeHeight_${placemarkIndex}">Execute Height (m):</label>
                    <input type="number" id="executeHeight_${placemarkIndex}" name="Placemark[${placemarkIndex}][executeHeight]" value="116.57">

                    <label for="waypointSpeed_${placemarkIndex}">Waypoint Speed (m/s):</label>
                    <input type="number" id="waypointSpeed_${placemarkIndex}" name="Placemark[${placemarkIndex}][waypointSpeed]" value="10">

                    <label for="waypointHeadingMode_${placemarkIndex}">Waypoint Heading Mode:</label>
                    <select id="waypointHeadingMode_${placemarkIndex}" name="Placemark[${placemarkIndex}][waypointHeadingMode]">
                        <option value="followWayline">Follow Wayline</option>
                        <!-- Add other options as needed -->
                    </select>

                    <label for="waypointTurnMode_${placemarkIndex}">Waypoint Turn Mode:</label>
                    <select id="waypointTurnMode_${placemarkIndex}" name="Placemark[${placemarkIndex}][waypointTurnMode]">
                        <option value="toPointAndStopWithDiscontinuityCurvature">To Point And Stop With Discontinuity Curvature</option>
                        <!-- Add other options as needed -->
                    </select>

                    <label for="waypointTurnDampingDist_${placemarkIndex}">Waypoint Turn Damping Dist (m):</label>
                    <input type="number" id="waypointTurnDampingDist_${placemarkIndex}" name="Placemark[${placemarkIndex}][waypointTurnDampingDist]" value="0">

                    <label for="gimbalYawRotateAngle_${placemarkIndex}">Gimbal Yaw Rotate Angle (°):</label>
                    <input type="number" id="gimbalYawRotateAngle_${placemarkIndex}" name="Placemark[${placemarkIndex}][gimbalYawRotateAngle]" value="30">

                    <label for="photoFileSuffix_${placemarkIndex}">Photo File Suffix:</label>
                    <input type="text" id="photoFileSuffix_${placemarkIndex}" name="Placemark[${placemarkIndex}][photoFileSuffix]" value="point1">
                </fieldset>
            `;
        console.log(123)
        placemarkFieldset.appendChild(newPlacemark);
    });

    document.getElementById('missionForm').addEventListener('submit', function(event) {
        event.preventDefault();

        const formData = new FormData(event.target);

        const jsonData = {
            missionConfig: {
                flyToWaylineMode: formData.get('flyToWaylineMode'),
                finishAction: formData.get('finishAction'),
                exitOnRCLost: formData.get('exitOnRCLost'),
                executeRCLostAction: formData.get('executeRCLostAction'),
                takeOffSecurityHeight: formData.get('takeOffSecurityHeight'),
                globalTransitionalSpeed: formData.get('globalTransitionalSpeed'),
                droneInfo: {
                    droneEnumValue: formData.get('droneEnumValue'),
                    droneSubEnumValue: formData.get('droneSubEnumValue')
                },
                payloadInfo: {
                    payloadEnumValue: formData.get('payloadEnumValue'),
                    payloadPositionIndex: formData.get('payloadPositionIndex')
                }
            },
            Folder: {
                templateId: formData.get('templateId'),
                executeHeightMode: formData.get('executeHeightMode'),
                waylineId: formData.get('waylineId'),
                autoFlightSpeed: formData.get('autoFlightSpeed'),
                Placemark: []
            }
        };

        const placemarkFieldset = document.getElementById('placemarkFieldset');
        for (let i = 0; i < placemarkFieldset.children
